package com.oj.judge.controller;

import com.oj.common.Result;
import com.oj.judge.domain.Submission;
import com.oj.judge.service.SubmissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Classname SubmissionController
 * @Description TODO
 * @Date 2025/3/16 18:25
 * @Created by xxx
 */
@Api(tags = "提交代码接口")
@RestController
@RequestMapping("/judge/submission")
public class SubmissionController {
    @Autowired
    private SubmissionService submissionService;

    /**
     * 提交代码接口
     */
    @ApiOperation(value = "提交代码接口", notes = "提交代码接口")
    @PostMapping
    public Result submitCode(@RequestBody Submission submission) {
        Integer id = submissionService.submitCode(submission).intValue();
        return Result.success("提交成功", id);
    }

    /**
     * 查询提交状态接口
     */
    @ApiOperation(value = "查询提交状态接口", notes = "查询提交状态接口")
    @GetMapping("/{id}")
    public Result getSubmission(@PathVariable Long id) {
        Submission submission = submissionService.getSubmissionById(id);
        return Result.success("查询成功", submission);
    }
}
